#coding:utf-8
import  csv
oldf="./data/home.csv"
nldf="./data/onlinehomepage.csv"

from enum import  IntEnum #枚举
class Data(IntEnum):
    LABLE = 0
    TIME  = 4
    ERROR = 9
    TPS   = 10

a={}
with open(oldf, encoding='utf-8' )as rf:
    reader=csv.reader(rf)
    # print(reader)
    for i in reader:
        # print(i)
        a[i[Data.LABLE]] = "" #构造字典a={} a['key']=''
    print( a )

    #方法二，列表生成式
    # reader=[ i[Data.LABLE] for i in reader]
    # a=a.fromkeys(reader,'')
    # print(a)



with open( nldf, encoding="utf-8" ) as rf: #获取原始数据集
    reader=csv.reader(rf)
    header=next(reader)#获取第一行数据
    for reads in list(reader):
        print(reads)
        if float(reads[Data.TIME]) > 1000 or (reads[Data.ERROR])!= '0.00%':
        # if reads[Data.ERROR]!= '0.00%':
            a[reads[Data.LABLE]] = [reads[Data.LABLE],reads[Data.TIME],reads[Data.ERROR],reads[Data.TPS]] #添加字典
        print(a)


    with open( 'data/homepage12345.csv', 'w', encoding='utf-8', newline='' ) as wf:
        writer=csv.writer(wf)
        writer.writerow([header[Data.LABLE],header[Data.TIME],header[Data.ERROR],header[Data.TPS]])
        for v in a.values():
            print(v)
            writer.writerow(v)